const app = getApp()
Component({
  properties: {
    show: {
      type: Boolean,
      value: false
    },
    item: {
      type: Object,
      value: {}
    }
  },
  data: {
    focus: false,
    value: '',
    placeholder: '',
    keyHeight: 0,
    safeBottom: 0
  },
  methods: {
    beforeOpen () {
      const { screenHeight, safeArea: { bottom } } = wx.$pro.getSystemInfoSync()
      this.setData({ safeBottom: screenHeight - bottom })
      let val = ''
      if (this.data.item && this.data.item.nickName) {
        val = `回复 ${this.data.item.nickName}`
      } else {
        val = '友善发言，理性讨论，阳光你我'
      }
      this.setData({ value: '', placeholder: val })
    },
    opened () {
      this.setData({ focus: true })
    },
    close () {
      this.setData({ focus: false })
      this.triggerEvent('close')
    },
    keyboardheightchange ({ detail: { height, duration } }) {
      console.log(height)
      this.setData({ keyHeight: height })
      if (height <= 0 && duration > 0) {
        this.close()
      }
    },
    changeInput ({ detail: { value } }) {
      this.setData({ value })
    },
    send () {
      this.triggerEvent('send', this.data.value)
    }
  },
})